n = int(input())
lst=[]
for i in range(n):
	temp = input().split()
	lst.append(temp)

#lst =[['ss', '74', '4', '4'], ['aa', '47', '7', '1'], ['sa', '51', '4', '1'], ['wa', '1', '2', '58']]
def get_result(lst):
	lst.sort(key= lambda x:(-int(x[1]),-int(x[2]),-int(x[3]),x[0]))
	return lst

ss=get_result(lst)

for i in range(4):
	print(lst[i][0])
